package com.example.movie_demo

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.SeekBar
import androidx.navigation.Navigation
import kotlinx.android.synthetic.main.fragment_music_edit.*
import java.io.Serializable

class MusicEditFragment : Fragment() {

    private lateinit var data:Data

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_music_edit, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        data = Data()

        play_all.setOnClickListener {
            with(Bundle()){
                putSerializable("data",data)
                EventUtil.appendEvent("play Music")
                Navigation.findNavController(it).navigate(R.id.action_navigation_home_to_navigation_musci_play,this)
            }
        }

        background_musics.onItemSelectedListener = object :AdapterView.OnItemSelectedListener{
            override fun onItemSelected(
                parent: AdapterView<*>?,
                view: View?,
                position: Int,
                id: Long
            ) {
                data.bgMusicIndex = position
                EventUtil.appendEvent("switch background music")
            }

            override fun onNothingSelected(parent: AdapterView<*>?) {
            }

        }

        musics1.onItemSelectedListener = object :AdapterView.OnItemSelectedListener{
            override fun onItemSelected(
                parent: AdapterView<*>?,
                view: View?,
                position: Int,
                id: Long
            ) {
                data.edffectMusic1Index = position
                EventUtil.appendEvent("switch effect music")
            }

            override fun onNothingSelected(parent: AdapterView<*>?) {
            }

        }
        musics2.onItemSelectedListener = object :AdapterView.OnItemSelectedListener{
            override fun onItemSelected(
                parent: AdapterView<*>?,
                view: View?,
                position: Int,
                id: Long
            ) {
                data.edffectMusic2Index = position
                EventUtil.appendEvent("switch effect music")
            }

            override fun onNothingSelected(parent: AdapterView<*>?) {
            }

        }
        musics3.onItemSelectedListener = object :AdapterView.OnItemSelectedListener{
            override fun onItemSelected(
                parent: AdapterView<*>?,
                view: View?,
                position: Int,
                id: Long
            ) {
                data.edffectMusic3Index = position
                EventUtil.appendEvent("switch effect music")
            }

            override fun onNothingSelected(parent: AdapterView<*>?) {
            }

        }

        seekBar1.setOnSeekBarChangeListener(object :SeekBar.OnSeekBarChangeListener{
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                data.edffectMusic1Progress = progress
                EventUtil.appendEvent("drag effect music progress")
            }

            override fun onStartTrackingTouch(seekBar: SeekBar?) {
            }

            override fun onStopTrackingTouch(seekBar: SeekBar?) {
            }

        })
        seekBar2.setOnSeekBarChangeListener(object :SeekBar.OnSeekBarChangeListener{
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                data.edffectMusic2Progress = progress
                EventUtil.appendEvent("drag effect music progress")
            }

            override fun onStartTrackingTouch(seekBar: SeekBar?) {
            }

            override fun onStopTrackingTouch(seekBar: SeekBar?) {
            }

        })
        seekBar3.setOnSeekBarChangeListener(object :SeekBar.OnSeekBarChangeListener{
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                data.edffectMusic3Progress = progress
                EventUtil.appendEvent("drag effect music progress")
            }

            override fun onStartTrackingTouch(seekBar: SeekBar?) {
            }

            override fun onStopTrackingTouch(seekBar: SeekBar?) {
            }

        })


    }






}